package ThreadDemo1;

import java.util.concurrent.Semaphore;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-10-16
 * Time: 11:33
 */
public class ThreadDemo29 {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(3);
        semaphore.acquire();
        System.out.println("执行一次 P 操作!");
        semaphore.acquire();
        System.out.println("执行一次 P 操作!");
        semaphore.acquire();
        System.out.println("执行一次 P 操作!");//信号量到0就会阻塞

        semaphore.release();
        System.out.println("执行一次 V 操作!");
    }
}
